import Vue from "vue";
import Vuex from "vuex";
import storage from "@/utils/storage";
import { communityAllList } from "@/api/community";
Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		/**是否在展示Toast中 */
		isShowToast: false,
		/**填写订单备注 */
		remark: [],
		/**分享链接 */
		shareLink: "",
		/**获取key表示验证通过 */
		verificationKey: "",
		/**分销员Id 如果当前账户从未登录过时记录 */
		distributionId: "",
		/**是否已登录 */
		hasLogin: storage.getHasLogin(),
		/**用户信息 */
		userInfo: storage.getUserInfo(),
		/**UUID */
		token: "",
		allListCommunity:'',//所有小区
	},
	mutations: {
		login(state, userInfo) {
			state.userInfo = userInfo || {};
			state.userName =
				userInfo.Name || userInfo.Nickname || userInfo.Username || "匿名用户";
			state.hasLogin = true;
		},
		logout(state) {
			state.userName = "";
			state.hasLogin = false;
		},

		/**
		 * 设置填写订单中备注
		 */
		setRemark(state, remark) {
			state.remark = remark;
		},
		/**
		 * 所有小区
		 */
		//设置所有小区
		SET_AllListCommunity: (state, value) => {
		  state.allListCommunity = value
		},
	},
	actions: {
		AllCommunityList({ commit, state }) {
		  return new Promise((resolve, reject) => {
			  communityAllList().then(res=>{
			  	commit('SET_AllListCommunity', res.data)
			  	resolve(res.data)
			  }).catch(error => {
		      reject(error)
		    })
		  })
		},
	},
});

export default store;